package com.bristua.barcode.supplier.controller;

import com.bristua.barcode.common.bean.Result;
import com.bristua.barcode.common.util.HandleResultUtil;
import com.bristua.barcode.customer.dao.TCustomerBindSupplierMapper;
import com.bristua.barcode.customer.dao.TCustomerMapper;
import com.bristua.barcode.customer.model.TCustomer;
import com.bristua.barcode.customer.model.TCustomerBindSupplier;
import com.bristua.barcode.customer.model.condition.TCustomerBindSupplierExample;
import com.bristua.barcode.supplier.model.vo.QuerySupplierQrcodeInfoVO;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by Administrator on 2019/8/30.
 */
@RestController
public class QueryQRcodeBindInfoController {
    @Resource
    private TCustomerBindSupplierMapper tCustomerBindSupplierMapper;

    @Resource
    private TCustomerMapper tCustomerMapper;

    @PostMapping(value = "/supplier/qrcode/bind/info/{qrcodeId}/{supplierId}")
    public Result queryQrcodeBindInfo(@PathVariable(value = "qrcodeId") String qrcodeId,@PathVariable(value = "supplierId") String supplierId){
        TCustomerBindSupplierExample tCustomerBindSupplierExample = new TCustomerBindSupplierExample();
        tCustomerBindSupplierExample.createCriteria().andSupplierIdEqualTo(supplierId).andQrCodeIdEqualTo(qrcodeId);
        List<TCustomerBindSupplier> tCustomerBindSuppliers = tCustomerBindSupplierMapper.selectByExample(tCustomerBindSupplierExample);
        if(tCustomerBindSuppliers!=null && tCustomerBindSuppliers.size()>0){
            TCustomerBindSupplier tCustomerBindSupplier = tCustomerBindSuppliers.get(0);
            String customerId = tCustomerBindSupplier.getCustomerId();
            TCustomer tCustomer = tCustomerMapper.selectByPrimaryKey(customerId);
            QuerySupplierQrcodeInfoVO querySupplierQrcodeInfoVO = new QuerySupplierQrcodeInfoVO();
            BeanUtils.copyProperties(tCustomer,querySupplierQrcodeInfoVO);
            return HandleResultUtil.querySuccessResult(querySupplierQrcodeInfoVO);
        }
        return null;
    }
}
